package com.gxa.autoparts.admin.service.impl;

import com.gxa.autoparts.admin.mapper.LogMapper;
import com.gxa.autoparts.admin.service.LogService;
import com.gxa.autoparts.core.pojo.Log;
import com.gxa.autoparts.core.service.impl.BaseServiceImpl;
import com.gxa.autoparts.core.util.IpUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.net.UnknownHostException;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

@Service("logService")
public class LogServiceImpl extends BaseServiceImpl<Log> implements LogService {
    @Resource
    private LogMapper logMapper;
    @Override
    public List<Map> selectAllLog(String time1, String time2, String name, String type, Integer page, Integer size) {
        return logMapper.selectAllLog(time1, time2, name, type, page, size);
    }

    @Override
    public List<Map> selectAllLog2(String time1, String time2, String name, String type) {
        return logMapper.selectAllLog2(time1, time2, name, type);
    }

    @Override
    public void insertLog(String desc, String adminName) throws UnknownHostException {
        Log log = new Log();
        log.setIpAddress(IpUtil.getIp());
        log.setAdminId(adminName);
        log.setOperationTime(new Timestamp(System.currentTimeMillis()));
        log.setOperationDesc(desc);
        this.insert(log);
    }
}
